/**
 *
 * @param dom 需要监听的dom
 * @param callback 进入视口后的回调函数
 */
const onIntoView = (dom: HTMLElement,callback: () => void) => {
  const observer = new IntersectionObserver(
    (entries) => {
      const entry = entries[0];
      if (entry.isIntersecting) {
        console.log("进入视口");
        callback();
      }
    },
    {
      root: null, //视口交叉
      // rootMargin:'0px',
      threshold: 0.1, //交叉比例
    }
  );
  observer.observe(dom);
};
export default onIntoView;
